package Mapper;

import entity.Food;
import entity.SearchRecord;
import org.apache.ibatis.annotations.*;

import java.time.LocalDate;
import java.util.List;

@Mapper
public interface RecordMapper {

    //功能:在历史记录功能中，插入新的查询记录
    //接口接收SearchRecord(包含search_record表的各项字段)
    @Insert("INSERT INTO search_record (record_id, user_id, id, search_time) VALUES (#{record.recordId}, #{record.userId}, #{record.id}, #{record.searchTime})")
    public void insertRecord(@Param("record") SearchRecord record);

    //功能:获取当前search_record表中最大record_id的值
    @Select("SELECT COALESCE(MAX(record_id), 0) + 1 FROM search_record")
    public int nextId();

    //功能:根据用户id查询历史记录
    @Select("select * from search_record where user_id = #{user_id}")
    public List<SearchRecord> findRecord(@Param("user_id") int userId);

    //功能:根据记录id查询时间
    @Select("select search_time from search_record where record_id = #{rid}")
    public LocalDate getRecordTime(@Param("rid") int rid);


    //功能:根据记录id删除记录
    @Delete("delete from search_record where record_id = #{rid}")
    public void deleteRecord(@Param("rid") int rid);
}